use craftdig_math::{BlkCoord, ChunkCoord};

use crate::block;
use crate::player::id::PlayerId;
use crate::world::map::ChunkState;

#[derive(Clone, Debug)]
pub struct Action {
    source: Source,
    data: ActionData,
}

impl Action {
    pub fn new(source: Source, data: ActionData) -> Self {
        Self { source, data }
    }

    pub fn source(&self) -> &Source {
        &self.source
    }

    pub fn data(&self) -> &ActionData {
        &self.data
    }
}

/// Data for each type of action.
#[derive(Clone, Debug)]
pub enum ActionData {
    /// Placing a block.
    PlaceBlock {
        pos: BlkCoord,
        new_state: block::state::BlockStateSnapshot,
    },

    /// Removing a block, replacing it with air.
    BreakBlock { pos: BlkCoord },
}

/// Describes how the action was initiated.
#[derive(Clone, Debug)]
pub enum Source {
    /// Player initiated this action.  Eventually this will include their UUID
    /// and some other information.
    Player(PlayerId),

    /// The block that initiated this action.
    Block(BlkCoord),

    /// Server initiated this action, possibly from some admin command.
    Server,
}
